﻿
using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Web.UI;

namespace AiXiu.WebSite
{
    public partial class Register : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            // 判断是否通过表单验证
            if (Page.IsValid)
            {
                // 验证码验证
                string captcha = txtCaptcha.Text;
                string captchaCode = Session["Captcha"] as string;
                if (!captcha.Equals(captchaCode))
                {
                    this.Alert("cptfail", "验证码错误！");
                    return;
                }
                // 实例化登录
                TBLogins login = new TBLogins();
                login.UserName = txtUserName.Text;
                login.MobileNumber = txtMobileNumber.Text;
                login.Password = txtPassword.Text;
                // 注册用户
                IUserManager userManager = new UserManager();
                OperResult operResult = userManager.Register(login);
                // 判断结果
                if (operResult.StatusCode == StatusCode.Succeed)
                {
                    this.AlertAndRedirect("regsuccess", "注册成功！", "Login.aspx");
                    return;
                }
                else
                {
                    this.Alert("regfail", operResult.Message ?? "注册失败！");
                    return;
                }
            }
        }
    }
}